package com.yanqu.road.server.cmd.activity.summerquiz.fromcross;

import com.yanqu.road.entity.activity.summergames.SummerGamesUserData;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SummerQuizProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.summergames.SummerGamesModule;
import com.yanqu.road.server.gameplayer.module.activity.summerquiz.SummerQuizModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_SUMMER_QUIZ_USER_GUESS_GET_REWARD_FROM_CROSS, desc = "竞猜领取奖励(跨服返还)")
public class SummerQuizGuessGetRewardFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        SummerQuizProto.SummerQuizGuessGetRewardRespMsg respMsg = SummerQuizProto.SummerQuizGuessGetRewardRespMsg.parseFrom(packet.getBytes());

        player.getModule(CurrencyModule.class).addCurrency(respMsg.getReward(), eLogMoneyType.SummerQuizActivity, eLogMoneyType.SummerQuizActivityGuessReward);

        SummerQuizProto.SummerQuizGuessGetRewardRespMsg.Builder toBuilder = respMsg.toBuilder();

        if(respMsg.getNum() > 0){
            SummerGamesUserData userData = player.getModule(SummerGamesModule.class).getUserData();
            if(userData != null){
                userData.setGuessScore(respMsg.getNum() + userData.getGuessScore());
                //player.notifyListener(eGamePlayerEventType.SummerGamesGuessScoreRank.getValue(), userData.getGuessScore());

                player.getModule(SummerGamesModule.class).syncUserData();

            }
        }

        player.sendPacket(Protocol.U_SUMMER_QUIZ_USER_GUESS_GET_REWARD, toBuilder);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
